home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / util / stopwatch.h < prev   
C/C++ Source or Header  |  2006-05-08  |  3KB  |  108 lines

  1. #ifndef __STOPWATCH_H
  2. #define __STOPWATCH_H
  3. #include "nscore.h"
  4. #include "prlog.h"
  5. #include "nsDeque.h"
  6.  
  7. #ifdef XP_MAC
  8. #define R__MAC
  9. #endif
  10.  
  11. #ifdef XP_UNIX
  12. #define R__UNIX
  13. #endif
  14.  
  15. #ifdef MOZ_PERF_METRICS
  16. #  define NS_RESET_AND_START_STOPWATCH(_sw)          \
  17.     _sw.Start(PR_TRUE);
  18.  
  19. #  define NS_START_STOPWATCH(_sw)                    \
  20.     _sw.Start(PR_FALSE);
  21.  
  22. #  define NS_STOP_STOPWATCH(_sw)                     \
  23.     _sw.Stop();
  24.  
  25. #  define NS_SAVE_STOPWATCH_STATE(_sw)               \
  26.     _sw.SaveState();
  27.  
  28. #  define NS_RESTORE_STOPWATCH_STATE(_sw)            \
  29.     _sw.RestoreState();
  30.  
  31. #else
  32. #  define NS_RESET_AND_START_STOPWATCH(_sw) 
  33. #  define NS_START_STOPWATCH(_sw)
  34. #  define NS_STOP_STOPWATCH(_sw)
  35. #  define NS_SAVE_STOPWATCH_STATE(_sw)
  36. #  define NS_RESTORE_STOPWATCH_STATE(_sw)
  37. #endif
  38.  
  39.  
  40. #ifdef MOZ_PERF_METRICS
  41.  
  42. static PRLogModuleInfo* gLogStopwatchModule = PR_NewLogModule("timing");
  43.  
  44. #if 0
  45. #define RAPTOR_TRACE_STOPWATCHES        0x1
  46.  
  47. #define RAPTOR_STOPWATCH_TRACE(_args)                               \
  48.   PR_BEGIN_MACRO                                                    \
  49.   PR_LOG(gLogStopwatchModule, RAPTOR_TRACE_STOPWATCHES, _args);     \
  50.   PR_END_MACRO
  51. #endif
  52.  
  53. #define RAPTOR_STOPWATCH_TRACE(_args)      \
  54.   PR_BEGIN_MACRO                           \
  55.   printf _args ;                           \
  56.   PR_END_MACRO
  57.  
  58. #else
  59. #define RAPTOR_TRACE_STOPWATCHES 
  60. #define RAPTOR_STOPWATCH_TRACE(_args) 
  61. #endif
  62.  
  63. #ifdef DEBUG_STOPWATCH
  64. #define RAPTOR_STOPWATCH_DEBUGTRACE(_args)      \
  65.   PR_BEGIN_MACRO                                \
  66.   printf _args ;                                \
  67.   PR_END_MACRO
  68. #else
  69. #define RAPTOR_STOPWATCH_DEBUGTRACE(_args) 
  70. #endif
  71.  
  72. class Stopwatch {
  73.  
  74. private:
  75.    enum EState { kUndefined, kStopped, kRunning };
  76.  
  77.    double         fStartRealTime;   //wall clock start time
  78.    double         fStopRealTime;    //wall clock stop time
  79.    double         fStartCpuTime;    //cpu start time
  80.    double         fStopCpuTime;     //cpu stop time
  81.    double         fTotalCpuTime;    //total cpu time
  82.    double         fTotalRealTime;   //total real time
  83.    EState         fState;           //stopwatch state
  84.    nsDeque*       mSavedStates;     //stack of saved states
  85.    PRBool         mCreatedStack;    //Initially false.  Set to true in first SaveState() call.
  86.  
  87. public:
  88.    Stopwatch();
  89.    virtual ~Stopwatch();
  90.  
  91.    void           Start(PRBool reset = PR_TRUE);
  92.    void           Stop();
  93.    void           Continue();
  94.    void           SaveState();      // record current state of stopwatch
  95.    void           RestoreState();   // restore last recored state of stopwatch
  96.    double         RealTime();
  97.    double         RealTimeInMilliseconds();
  98.    void           Reset() { ResetCpuTime(); ResetRealTime(); }
  99.    void           ResetCpuTime(double aTime = 0) { Stop();  fTotalCpuTime = aTime; }
  100.    void           ResetRealTime(double aTime = 0) { Stop(); fTotalRealTime = aTime; }
  101.    double         CpuTime();
  102.    void           Print(void);
  103.    static double  GetRealTime();
  104.    static double  GetCPUTime();
  105.  
  106. };
  107. #endif
  108.